home *** CD-ROM | disk | FTP | other *** search
- Path: zib-berlin.de!uniol!news
- From: Ingo.Wilken@Informatik.Uni-Oldenburg.DE (Ingo Wilken)
- Newsgroups: comp.sys.amiga.programmer
- Subject: Re: My code crashes my computer
- Date: 17 Mar 96 21:42:27 GMT
- Organization: C. v. Ossietzky Universitaet Oldenburg - Fachbereich Informatik
- Message-ID: <4ii1jk$j8h@news.Informatik.Uni-Oldenburg.DE>
- References: <4igm25$poj@goofy.BrandonU.CA>
- NNTP-Posting-Host: rubin.informatik.uni-oldenburg.de
- X-Newsreader: NN version 6.5.0 #2 (NOV)
-
- menon@beijing.brandonu.ca writes:
- >void read_file(char *infile, char *infile2){
- > int i=0, x, y, garb;
- > FILE *fp;
- > char *s="File Error";
- > char *comment="", buf;
-
- > fgets(type,3,fp);
-
- 'type' is not defined...
-
- > fscanf(fp,"%s",comment);
-
- 'comment' points to a space of 1 byte (the string "" above), which most
- likely is not even writeable because it is into the code section of your
- program... although you don't notice this easily because the Amiga does
- not use the MMU to make code sections read-only.
-
- > if (comment[0]=='#'){
- > do{
- > fscanf(fp, "%s",comment);
-
- Same here.
-
- > sprintf(buf,"%d",atoi(comment)); <---Crashes Here
-
- No wonder. First, 'buf' is only 1 byte long (type char), and even if the
- sprintf() call actually writes only an single integer digit, it adds a '\0'
- - thats already two characters. Second, sprintf() requires an _array_ or
- a pointer to an _allocated_ memory buffer as the first argument, not only
- a single character. The compiler should have given you at least a warning
- here.
-
- > }
- > while (strcmp(comment,buf));
-
- >I compile it using:
- >gcc -o corr corr.c -m68040 -m68881
-
- Try the options "-Wall -pedantic -ansi".
-
- >If anyone can help me, I would greatly appreciate it.
-
- Get a good book on C (for example K&R 2), and learn about pointers and arrays.
-
-
- Regards,
- Ingo
- --
- Ingo Wilken, CS Student, Univ.of Oldenburg, FRG | I'll admit dat I'm not one
- http://www.informatik.uni-oldenburg.de/~ingo/ | of da beautiful people, but
- E-mail: Ingo.Wilken@informatik.uni-oldenburg.de | I'm not as ugly as da spooks
- IRC: Nobody or TeaMan | dat hang 'round here. -Snarf
-